package com.example.demo.dao;

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;


@Repository
public class BookDao {
    @Cacheable(value = "c1")
    public String getBookById(Integer id) {
        System.out.printf("\r\n");
        System.out.printf("getBookById");
        System.out.printf("从方法中获取:");
        return "this is a book";
    }

    @CachePut(value = "c1")
    public String updateBookById(Integer id) {
        System.out.printf("\r\n");
        System.out.printf("从方法中更新:");
        return "this is a new book";
    }

    @CacheEvict(value = "c1")
    public void deleteById(Integer id) {
        System.out.printf("\r\n");
        System.out.printf("deleteById");
        System.out.printf("从方法中删除:");
    }

    @Cacheable(value = "c3")
    public String getBookById2(Integer id) {
        System.out.printf("\r\n");
        System.out.printf("getBookById2");
        System.out.printf("从方法中获取:");
        return "this is a new book2";
    }
}
